﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Taxi_taxi.ViewModels
{
    internal class TaxiViewModel
    {
        TaxiClient client;

        ObservableCollection<TaiXe> listTaiXe;

        public ObservableCollection<TaiXe> ListTaiXe
        {
            get { return listTaiXe; }
            set 
            { 
                listTaiXe = value;
                NotifyPropertyChanged("ListTaiXe");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void GetTaiXeByLocation(double x, double y)
        {
            client = new TaxiClient();
            client.GetTaiXeByLocationAsync(x, y);
            client.GetTaiXeByLocationCompleted += client_GetTaiXeByLocationCompleted;
        }

        void client_GetTaiXeByLocationCompleted(object sender, GetTaiXeByLocationCompletedEventArgs e)
        {
            ListTaiXe = e.Result;

                if (OnGetListTaiXeCompleted != null)
                    OnGetListTaiXeCompleted(this);
        }

        public delegate void GetListTaiXeCompleted(object sender);
        public GetListTaiXeCompleted OnGetListTaiXeCompleted;
    }
}
